#include "main.h"

// 外设时钟enable
void clock_enable(void)
{
    CCM_CCGR0 = 0xffffffff;
    CCM_CCGR1 = 0xffffffff;
    CCM_CCGR2 = 0xffffffff;
    CCM_CCGR3 = 0xffffffff;
    CCM_CCGR4 = 0xffffffff;
    CCM_CCGR5 = 0xffffffff;
    CCM_CCGR6 = 0xffffffff;
}

void led_init(void)
{
    SW_MUX_GPIO1_IO03 = 0x05;
    SW_PAD_GPIO1_IO03 = 0x10b0;
    GPIO1_GDIR = 0x8;
    GPIO1_DR = 0x0;
}

void delay_short(volatile unsigned int count)
{
    while (count--);
}

void delay_ms(volatile unsigned int ms)
{
    while (ms--)
    {
        delay_short(0x7ff);
    }
}

void led_on(void)
{
    GPIO1_DR &= ~(1 << 3);
}

void led_off(void)
{
    GPIO1_DR |= (1 << 3);
}

int main(void)
{
    clock_enable();
    led_init();

    while(1)
    {
        led_on();
        delay_ms(1000);

        led_off();
        delay_ms(1000);
    }

    return 0;
}